# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         task3
# Description:
# Author:       $赵怡蕾
# Date:         2019/4/13
#-------------------------------------------------------------------------------

'''
斗地主
要求1号的牌最好
采用面向对象的方法写
'''

order = 1  # 牌排列顺序 默认为1 即从小到大顺序排列  0：从大到小排列
Player_Num = 3  # 三名玩家
N = 54  # 一副牌有54张（包含大小王）
times = 1  # 一副牌
leftover = 3  # 3张底牌

import random

card0 = list(range(0, N))
card0 = card0 * times
# print(card0)
schar = '♠♥♣♦♛♚'
card1 = []
left = N * times
for i in range(N * times):
    rdi = random.randint(0, left - 1)
    card1.append(card0[rdi])
    card0.pop(rdi)
    left -= 1
    if left == 0:
        break
# print(card1)
Player = []
for i in range(Player_Num):
    Player.append([])
for i in range(N * times - leftover):
    Player[i % Player_Num].append(card1[i])
Player.append([])
for i in range(N * times - leftover, N * times):
    Player[Player_Num].append(card1[i])
for i in range(Player_Num + 1):
       # print(Player[i])
    Player[i].sort()
    if order == 0:
        Player[i].reverse()
   # print(Player[i])
card_output = []
for i in range(Player_Num + 1):
    card_output.append([])
for i in range(Player_Num + 1):
    for j in range(len(Player[i])):
        if Player[i][j] == 53 or Player[i][j] == 52:
            card_output[i].append(str(schar[Player[i][j] % 2 + 4]).rjust(3))
        else:
            cardnumber = (Player[i][j] // 4 + 2) % 13 + 1
            cardflower = 3 - Player[i][j] % 4
            if cardnumber == 1:
                card_output[i].append('A'.rjust(2) + str(schar[cardflower]))
            elif cardnumber == 11:
                card_output[i].append('J'.rjust(2) + str(schar[cardflower]))
            elif cardnumber == 12:
                card_output[i].append('Q'.rjust(2) + str(schar[cardflower]))
            elif cardnumber == 13:
                card_output[i].append('K'.rjust(2) + str(schar[cardflower]))
            else:
                card_output[i].append(str(cardnumber).rjust(2) + str(schar[cardflower]))
# print(card_output)
for i in range(Player_Num):
    print('玩家{:>2}的手牌为:'.format(i + 1), ' '.join(card_output[i]))
print('剩余的{}张底牌为:'.format(leftover), ' '.join(card_output[Player_Num]))
# for i in range(Player_Num + 1):
#    print(Player[i])

# 统计炸弹数目

boom = []
for i in range(Player_Num + 1):
    boom.append([])
count = 0
last_cardnumber = -1
for i in range(Player_Num + 1):
    if 53 in Player[i] and 52 in Player[i]:
        boom[i].append('炸弹{}: 王炸'.format(len(boom[i]) + 1))
    for data in Player[i]:
        if data == 53 or data == 52:
            continue
        else:
            cardnumber = (data // 4 + 2) % 13 + 1
            if last_cardnumber == cardnumber:
                count += 1
            else:
                if count >= 3:
                    if last_cardnumber == 1:
                        last_cardnumber = 'A'.rjust(2)
                    elif last_cardnumber == 11:
                        last_cardnumber = 'J'.rjust(2)
                    elif last_cardnumber == 12:
                        last_cardnumber = 'Q'.rjust(2)
                    elif last_cardnumber == 13:
                        last_cardnumber = 'K'.rjust(2)
                    else:
                        last_cardnumber = str(last_cardnumber).rjust(2)
                    boom[i].append('炸弹{}:{}个{:>2}'.format(len(boom[i]) + 1, count + 1, last_cardnumber))
                count = 0
                last_cardnumber = cardnumber
boom_num = 0  # 炸弹数目
for i in range(Player_Num):
    if len(boom[i]) != 0:
        print('玩家{:>2}有{:>2}个炸弹，为:'.format(i + 1, len(boom[i])), '   '.join(boom[i]))
        boom_num += 1
if len(boom[Player_Num]) != 0:
    print('底牌中有{:>2}个炸弹，为:'.format(len(boom[Player_Num])), '   '.join(boom[Player_Num]))
    boom += 1
if boom_num == 0:
    print('本局未产生炸弹')